home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / nurbsCurveInformation.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.7 KB  |  189 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // get lots of information about a nurbs curve
  18. proc float[] getNurbsCurveKnots( 
  19.     string $crvName )
  20. //
  21. //    Description :
  22. //
  23. {
  24.     float $knots[] ;
  25.     string $infoNode ;
  26.  
  27.     // create info Node.
  28.     if( catch( $infoNode = `createNode curveInfo` ) ) {
  29.         return $knots ;
  30.     } 
  31.  
  32.     // connect curve on to the info node.
  33.     //
  34.     string $outAttr = $crvName + ".local" ; 
  35.     string $inAttr = $infoNode + ".ic" ;
  36.     connectAttr $outAttr $inAttr ;
  37.  
  38.     // read the knots.
  39.     //
  40.     $outAttr = $infoNode + ".knots" ; 
  41.     $knots = `getAttr $outAttr` ;    
  42.  
  43.     // delete curve info node.
  44.     //
  45.     delete $infoNode ;
  46.  
  47.     // return the knots.
  48.     //
  49.     return $knots;
  50. }
  51.  
  52. global proc printNurbsCurveMiscInfo(string $crv)
  53. // Description :
  54. //  prints the knot values
  55. {
  56.     // form
  57.     int $form = eval("getAttr " + $crv + ".form");
  58.     $w = "Form: " + $form + " (0 = open, 1 = closed, 2 = periodic)\n";
  59.     print $w;
  60.     
  61.     // degree
  62.     int $degree = eval("getAttr " + $crv + ".degree");
  63.     $w = "Degree: " + $degree + "\n";
  64.     print $w;
  65.     
  66.     // number of spans
  67.     int $nspans = eval("getAttr " + $crv + ".spans");
  68.     $w = "Nspans: " + $nspans + "\n";
  69.     print $w;
  70.     
  71.     // bounding box (what if it is 2d??)
  72.     float $minBox[] = eval("getAttr " + $crv + ".boundingBoxMin");
  73.     $w = "Bounding box min: " + $minBox[0] + " " + $minBox[1] + " " + $minBox[2] + "\n";
  74.     print $w;
  75.     
  76.     float $maxBox[] = eval("getAttr " + $crv + ".boundingBoxMax");
  77.     $w = "             max: " + $maxBox[0] + " " + $maxBox[1] + " " + $maxBox[2] + "\n";
  78.     print $w;
  79.     
  80. }
  81.  
  82. global proc printNurbsCurveKnots(string $crv)
  83. // Description :
  84. //  prints the knot values
  85. {
  86.  
  87.     float $knots[] = getNurbsCurveKnots($crv);
  88.     print "Knots: ";
  89.     int $numKnots = size($knots);
  90.     for($i=0; $i<$numKnots; $i++) {
  91.         $w = " " + $knots[$i];
  92.         print $w;
  93.     }
  94.     print "\n";
  95.         
  96. }
  97.  
  98. global proc printNurbsCurveCVs(string $crv)
  99. // Description :
  100. //  prints the CV positions in world space
  101. {
  102.         
  103.     // create info Node.
  104.     string $infoNode = `createNode curveInfo`;
  105.     
  106.     // connect curve on to the info node.
  107.     string $outAttr = $crv + ".ws[0]" ;
  108.     string $inAttr = $infoNode + ".ic" ;
  109.     connectAttr $outAttr $inAttr ;
  110.     
  111.     // CVs 
  112.     int $numCVs = `getAttr -size ($infoNode + ".cp")`;
  113.     
  114.     $w = "Number of CVs: " + $numCVs + "\n";
  115.     print $w;
  116.     
  117.     float $cv0[] = `getAttr ($infoNode + ".cp[0]")`;
  118.     int $dim = size($cv0);
  119.     $w = "Dimension of curve: " + $dim + "\n";
  120.     print $w;
  121.     
  122.     // print out the CV positions
  123.     print "CVs in world space:\n";
  124.     for($i=0; $i<$numCVs; $i++) {
  125.         float $cvs[] = `getAttr ($infoNode + ".cp[" + $i + "]")`;
  126.         $w = $i + ": ";
  127.         for($j=0; $j<$dim; $j++) {
  128.             $w +=  $cvs[$j] + " ";
  129.         }
  130.         $w += "\n";
  131.         print $w;
  132.     }
  133.     
  134.     // tidy up
  135.     delete $infoNode ;
  136. }
  137.  
  138. global proc nurbsCurveInformation()
  139. {
  140.     string $w; // for messages
  141.  
  142.     // 0. Grab the select list.
  143.     //
  144.     string $selList[] = `ls -sl`;
  145.  
  146.     // 1. Run filter to select only the NURBS curves and curves on surface
  147.     //
  148.     global int $gSelectNurbsCurvesBit ;
  149.     global int $gSelectCurvesOnSurfacesBit;
  150.  
  151.     string $crvList[] = `filterExpand -ex true 
  152.         -sm $gSelectNurbsCurvesBit 
  153.         -sm $gSelectCurvesOnSurfacesBit $selList` ;    
  154.     int $len = size($crvList) ;
  155.     if( $len == 0 ) {
  156.         print "No NURBS curve selected" ;
  157.         return;
  158.     }
  159.  
  160.     // 2. Work on the last item if more than one NURBS curve in list.
  161.     //
  162.     for($crvNum = 0; $crvNum < $len; $crvNum++) {
  163.         string $crv = $crvList[$crvNum] ;
  164.  
  165.         // print separator if more than one curve
  166.         if($len>1) print "----------------------------------\n";
  167.  
  168.         // curve name
  169.         $w = "Curve: " + $crv + "\n";
  170.         print $w;
  171.         
  172.         // print out the form,degree,nspans,bbox
  173.         printNurbsCurveMiscInfo($crv);
  174.  
  175.         // print out the knots
  176.         printNurbsCurveKnots($crv);
  177.  
  178.         // print out the CVs
  179.         printNurbsCurveCVs($crv);
  180.     }
  181.  
  182.     // print separator if more than one curve
  183.     if($len>1) print "----------------------------------\n";
  184.  
  185.     // reselect curve for which information was returned
  186.     select -r $selList;
  187. }
  188.  
  189.